﻿using System;
/*
 * 源码己托管: http://gitee.com/dlgcy/dotnetcodes
 * 版本：2024年4月14日
 */
namespace DotNet.Utilities.Results.D
{
    /// <summary>
    /// 结果消息
    /// </summary>
    public class ResultMsg
    {
        /// <summary>
        /// 消息内容或报错信息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 异常
        /// </summary>
        public Exception Exception { get; set; }

        /// <summary>
        /// 返回失败消息
        /// </summary>
        public static ResultMsg FailMsg(string msg, Exception ex = null)
        {
            return new ResultMsg { IsSuccess = false, Message = msg, Exception = ex };
        }

        /// <summary>
        /// 返回成功消息
        /// </summary>
        public static ResultMsg SuccessMsg(string msg = "")
        {
            return new ResultMsg { IsSuccess = true, Message = msg };
        }
    }

    /// <summary>
    /// 结果数据
    /// </summary>
    public class ResultData<T> : ResultMsg
    {
        /// <summary>
        /// 数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 返回失败结果
        /// </summary>
        public static ResultData<T> FailResult(string msg, T data = default, Exception ex = null)
        {
            return new ResultData<T> { Message = msg, IsSuccess = false, Data = data, Exception = ex };
        }

        /// <summary>
        /// 返回成功结果
        /// </summary>
        public static ResultData<T> SuccessResult(T data, string msg = "")
        {
            return new ResultData<T> { IsSuccess = true, Data = data, Message = msg };
        }
    }
}
